<template>
  <div class="app-container">
    <!--工具栏-->
    <crudOperation :permission="permission" />
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
<!--        <el-form size="small" label-width="70px">-->
<!--          <el-row :gutter="10">-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户名称">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售部门">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="销售人员">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户分类">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="客户区域">-->
<!--                <el-input></el-input>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <rrOperation :crud="crud"/>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
      </div>
      <el-dialog v-dialog-drag style="width: 80vm" title="搜索"   close-on-click-modal :visible.sync="crud.props.searchToggle"
                 width="70%">
        <el-form size="small" label-width="70px" >
          <el-row :gutter="10">
            <el-col span="12">
              <el-form-item label="日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    style="width: 50%"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据编号">
                <el-input v-model="query.orderCode" placeholder="输入编码进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col span="6">
              <el-form-item label="单据类型">
                <el-select v-model="orderType" collapse-tags multiple class="edit-input" placeholder="请选择单据状态" style="width: 100%;">
                  <el-option
                    v-for="(item,index) in dict.t_report_buy_statistics_order_type"
                    :key="index"
                    multiple
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col span="6">
              <el-form-item label="供应商">
                <table-select
                  :tableColumns="
                  [
                  {prop:'code',label:'供应商编码',width: '100'},
                  {prop:'name',label:'供应商名称',width: '150'},
                  ]"
                  labelKey="name"
                  valueKey="id"
                  width="440"
                  :value.sync="query.customerIds"
                  placeholder="请选择客户"
                  url="api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品名称">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品品牌">
                <table-select
                  :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                  :value.sync="query.goodsBrandIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basGoodsBrandList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品分类">
                <treeselect
                  v-model="goodsTypeIds"
                  :options="areaList"
                  placeholder="商品"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="仓库">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.warehouseIds"
                  placeholder="请选择仓库"
                  url="/api/dropDown/basWarehouseList"
                ></table-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
              <el-form-item label="小计列">
                <el-checkbox-group style="flex-wrap: wrap"
                  v-model="groupColumn" @change="getChange" class="flex flex-row ">
                  <el-checkbox v-for="item in groupColumnList"
                               :disabled="item.value ==''"
                               :label="item.value" :key="item.value"
                               :value="item.value" >{{item.label}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row class="flex fow-reverse" >
            <el-button class="filter-item"  size="mini" type="primary" @click="queryReport">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery" >重置</el-button>
          </el-row>
        </el-form>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="业务日期">
            <el-input v-model="form.busDate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据类型(1:采购订单 2:采购退货)">
            <el-input v-model="form.orderType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="供应商id">
            <el-input v-model="form.customerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="供应商编码">
            <el-input v-model="form.customerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="供应商名称">
            <el-input v-model="form.customerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店id">
            <el-input v-model="form.pCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店编码">
            <el-input v-model="form.pCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属总店名称">
            <el-input v-model="form.pCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场id">
            <el-input v-model="form.mCustomerId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场编码">
            <el-input v-model="form.mCustomerCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属商场名称">
            <el-input v-model="form.mCustomerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门id">
            <el-input v-model="form.deptId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门编码">
            <el-input v-model="form.deptCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="部门名称">
            <el-input v-model="form.deptName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员id">
            <el-input v-model="form.userId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员编码">
            <el-input v-model="form.userCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="人员名称">
            <el-input v-model="form.userName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库id">
            <el-input v-model="form.warehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库编码">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="form.goodsId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品编码">
            <el-input v-model="form.goodsCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.goodsName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装类型(1:纸箱 2:塑箱 3:其他)">
            <el-input v-model="form.packageType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="条形码">
            <el-input v-model="form.barcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱装条形码">
            <el-input v-model="form.boxBarcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="助记符">
            <el-input v-model="form.helpSign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌id">
            <el-input v-model="form.goodsBrandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌编码">
            <el-input v-model="form.goodsBrandCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌名称">
            <el-input v-model="form.goodsBrandName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类id">
            <el-input v-model="form.goodsTypeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类编码">
            <el-input v-model="form.goodsTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类名称">
            <el-input v-model="form.goodsTypeName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型id">
            <el-input v-model="form.goodsTagId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型编码">
            <el-input v-model="form.goodsTagCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型名称">
            <el-input v-model="form.goodsTagName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位id">
            <el-input v-model="form.boxUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位编码">
            <el-input v-model="form.boxUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位名称">
            <el-input v-model="form.boxUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数单位计量数">
            <el-input v-model="form.boxUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位数量">
            <el-input v-model="form.boxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位id">
            <el-input v-model="form.mainUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位编码">
            <el-input v-model="form.mainUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位名称">
            <el-input v-model="form.mainUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位计量数">
            <el-input v-model="form.mainUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位数量">
            <el-input v-model="form.mainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="form.goodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数">
            <el-input v-model="form.boxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税单价">
            <el-input v-model="form.taxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税单价">
            <el-input v-model="form.noTaxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税箱价">
            <el-input v-model="form.taxBoxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税箱价">
            <el-input v-model="form.noTaxBoxPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="含税金额">
            <el-input v-model="form.taxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未税金额">
            <el-input v-model="form.noTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="税额">
            <el-input v-model="form.tax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="form.enterGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱数">
            <el-input v-model="form.enterBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱单位数量">
            <el-input v-model="form.enterBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库主单位数量">
            <el-input v-model="form.enterMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库含税金额">
            <el-input v-model="form.enterTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库未税金额">
            <el-input v-model="form.enterNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库税额">
            <el-input v-model="form.enterTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库数量">
            <el-input v-model="form.returnGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱数">
            <el-input v-model="form.returnBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱单位数量">
            <el-input v-model="form.returnBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库主单位数量">
            <el-input v-model="form.returnMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库含税金额">
            <el-input v-model="form.returnTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库未税金额">
            <el-input v-model="form.returnNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库税额">
            <el-input v-model="form.returnTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收数量">
            <el-input v-model="form.acceptGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱数">
            <el-input v-model="form.acceptBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收箱单位数量">
            <el-input v-model="form.acceptBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收主单位数量">
            <el-input v-model="form.acceptMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收含税金额">
            <el-input v-model="form.acceptTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收未税金额">
            <el-input v-model="form.acceptNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="验收税额">
            <el-input v-model="form.acceptTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="已核销金额">
            <el-input v-model="form.cancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="未核销金额">
            <el-input v-model="form.unCancelAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="header"  @tabSave="saveHead" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" stripe border :data="crud.data" size="small"
                style="width: 100%;"
                show-summary
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                height="700"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 10px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.busDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column v-if="columns.visible('orderType')" prop="orderType" label="单据类型(1:采购订单 2:采购退货)" />-->
<!--        <el-table-column v-if="columns.visible('customerId')" prop="customerId" label="供应商id" />-->
<!--        <el-table-column v-if="columns.visible('customerCode')" prop="customerCode" label="供应商编码" />-->
<!--        <el-table-column v-if="columns.visible('customerName')" prop="customerName" label="供应商名称" />-->
<!--        <el-table-column v-if="columns.visible('pCustomerId')" prop="pCustomerId" label="所属总店id" />-->
<!--        <el-table-column v-if="columns.visible('pCustomerCode')" prop="pCustomerCode" label="所属总店编码" />-->
<!--        <el-table-column v-if="columns.visible('pCustomerName')" prop="pCustomerName" label="所属总店名称" />-->
<!--        <el-table-column v-if="columns.visible('mCustomerId')" prop="mCustomerId" label="所属商场id" />-->
<!--        <el-table-column v-if="columns.visible('mCustomerCode')" prop="mCustomerCode" label="所属商场编码" />-->
<!--        <el-table-column v-if="columns.visible('mCustomerName')" prop="mCustomerName" label="所属商场名称" />-->
<!--        <el-table-column v-if="columns.visible('deptId')" prop="deptId" label="部门id" />-->
<!--        <el-table-column v-if="columns.visible('deptCode')" prop="deptCode" label="部门编码" />-->
<!--        <el-table-column v-if="columns.visible('deptName')" prop="deptName" label="部门名称" />-->
<!--        <el-table-column v-if="columns.visible('userId')" prop="userId" label="人员id" />-->
<!--        <el-table-column v-if="columns.visible('userCode')" prop="userCode" label="人员编码" />-->
<!--        <el-table-column v-if="columns.visible('userName')" prop="userName" label="人员名称" />-->
<!--        <el-table-column v-if="columns.visible('warehouseId')" prop="warehouseId" label="仓库id" />-->
<!--        <el-table-column v-if="columns.visible('warehouseCode')" prop="warehouseCode" label="仓库编码" />-->
<!--        <el-table-column v-if="columns.visible('warehouseName')" prop="warehouseName" label="仓库名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsId')" prop="goodsId" label="商品id" />-->
<!--        <el-table-column v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" />-->
<!--        <el-table-column v-if="columns.visible('packageType')" prop="packageType" label="包装类型(1:纸箱 2:塑箱 3:其他)" />-->
<!--        <el-table-column v-if="columns.visible('barcode')" prop="barcode" label="条形码" />-->
<!--        <el-table-column v-if="columns.visible('boxBarcode')" prop="boxBarcode" label="箱装条形码" />-->
<!--        <el-table-column v-if="columns.visible('helpSign')" prop="helpSign" label="助记符" />-->
<!--        <el-table-column v-if="columns.visible('model')" prop="model" label="规格型号" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandId')" prop="goodsBrandId" label="商品品牌id" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandCode')" prop="goodsBrandCode" label="商品品牌编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="商品品牌名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeId')" prop="goodsTypeId" label="商品分类id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeCode')" prop="goodsTypeCode" label="商品分类编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="商品分类名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagId')" prop="goodsTagId" label="商品类型id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagCode')" prop="goodsTagCode" label="商品类型编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagName')" prop="goodsTagName" label="商品类型名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="箱单位id" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCode')" prop="boxUnitCode" label="箱单位编码" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitName')" prop="boxUnitName" label="箱单位名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱数单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('boxNum')" prop="boxNum" label="箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitId')" prop="mainUnitId" label="主单位id" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCode')" prop="mainUnitCode" label="主单位编码" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="主单位名称" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCount')" prop="mainUnitCount" label="主单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('mainNum')" prop="mainNum" label="主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('goodsCount')" prop="goodsCount" label="数量" />-->
<!--        <el-table-column v-if="columns.visible('boxCount')" prop="boxCount" label="箱数" />-->
<!--        <el-table-column v-if="columns.visible('taxPrice')" prop="taxPrice" label="含税单价" />-->
<!--        <el-table-column v-if="columns.visible('noTaxPrice')" prop="noTaxPrice" label="未税单价" />-->
<!--        <el-table-column v-if="columns.visible('taxBoxPrice')" prop="taxBoxPrice" label="含税箱价" />-->
<!--        <el-table-column v-if="columns.visible('noTaxBoxPrice')" prop="noTaxBoxPrice" label="未税箱价" />-->
<!--        <el-table-column v-if="columns.visible('taxAmount')" prop="taxAmount" label="含税金额" />-->
<!--        <el-table-column v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额" />-->
<!--        <el-table-column v-if="columns.visible('tax')" prop="tax" label="税额" />-->
<!--        <el-table-column v-if="columns.visible('enterGoodsCount')" prop="enterGoodsCount" label="入库数量" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxCount')" prop="enterBoxCount" label="入库箱数" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxNum')" prop="enterBoxNum" label="入库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterMainNum')" prop="enterMainNum" label="入库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterTaxAmount')" prop="enterTaxAmount" label="入库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterNoTaxAmount')" prop="enterNoTaxAmount" label="入库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterTax')" prop="enterTax" label="入库税额" />-->
<!--        <el-table-column v-if="columns.visible('returnGoodsCount')" prop="returnGoodsCount" label="出库数量" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxCount')" prop="returnBoxCount" label="出库箱数" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxNum')" prop="returnBoxNum" label="出库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnMainNum')" prop="returnMainNum" label="出库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnTaxAmount')" prop="returnTaxAmount" label="出库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnNoTaxAmount')" prop="returnNoTaxAmount" label="出库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnTax')" prop="returnTax" label="出库税额" />-->
<!--        <el-table-column v-if="columns.visible('acceptGoodsCount')" prop="acceptGoodsCount" label="验收数量" />-->
<!--        <el-table-column v-if="columns.visible('acceptBoxCount')" prop="acceptBoxCount" label="验收箱数" />-->
<!--        <el-table-column v-if="columns.visible('acceptBoxNum')" prop="acceptBoxNum" label="验收箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('acceptMainNum')" prop="acceptMainNum" label="验收主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('acceptTaxAmount')" prop="acceptTaxAmount" label="验收含税金额" />-->
<!--        <el-table-column v-if="columns.visible('acceptNoTaxAmount')" prop="acceptNoTaxAmount" label="验收未税金额" />-->
<!--        <el-table-column v-if="columns.visible('acceptTax')" prop="acceptTax" label="验收税额" />-->
<!--        <el-table-column v-if="columns.visible('cancelAmount')" prop="cancelAmount" label="已核销金额" />-->
<!--        <el-table-column v-if="columns.visible('unCancelAmount')" prop="unCancelAmount" label="未核销金额" />-->
<!--        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />-->
<!--        <el-table-column v-permission="['admin','reportBuyStatistics:edit','reportBuyStatistics:del']" label="操作" width="150px" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
<!--      <el-pagination-->
<!--        :current-page.sync="query.page"-->
<!--        :page-size.sync="query.size"-->
<!--        :total="crud.page.total"-->
<!--        layout="prev, pager, next"-->
<!--        style="margin-top: 8px; position: fixed;bottom:35px"-->
<!--        @size-change="onGet"-->
<!--        @current-change="onGet"-->
<!--      />-->
    </div>
  </div>
</template>

<script>
import crudReportBuyStatistics from '@/api/erp/reportBuyStatistics'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import Treeselect from '@riophae/vue-treeselect'
import {get} from '@/api/erp/reportBuyStatistics'
import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
// import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";
import { manyTableMixin } from '../../../../mixins/manyTableMixin'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '采购统计报表',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false
  },
  queryOnPresenterCreated:false,
  url: 'api/reportBuyStatistics', sort: '',
  crudMethod: { ...crudReportBuyStatistics }})
const defaultForm = { busDate: null, orderType: null, customerId: null, customerCode: null, customerName: null, pCustomerId: null, pCustomerCode: null, pCustomerName: null, mCustomerId: null, mCustomerCode: null, mCustomerName: null, deptId: null, deptCode: null, deptName: null, userId: null, userCode: null, userName: null, warehouseId: null, warehouseCode: null, warehouseName: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, boxNum: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, mainNum: null, goodsCount: null, boxCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, taxAmount: null, noTaxAmount: null, tax: null, enterGoodsCount: null, enterBoxCount: null, enterBoxNum: null, enterMainNum: null, enterTaxAmount: null, enterNoTaxAmount: null, enterTax: null, returnGoodsCount: null, returnBoxCount: null, returnBoxNum: null, returnMainNum: null, returnTaxAmount: null, returnNoTaxAmount: null, returnTax: null, acceptGoodsCount: null, acceptBoxCount: null, acceptBoxNum: null, acceptMainNum: null, acceptTaxAmount: null, acceptNoTaxAmount: null, acceptTax: null, cancelAmount: null, unCancelAmount: null, id: null }
export default {
  name: 'ReportBuyStatistics',
  components: { pagination, crudOperation, rrOperation, udOperation ,Treeselect,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,manyTableMixin],
  dicts:['t_report_buy_statistics_order_type','common_order_status'],
  mounted(){
    this.crud.props.searchToggle =false
  },
  created() {
    getBasGoodsTypeTree({size:999}).then(res=>{
      this.areaList = res.data
    })
  },
  data() {
    return {
      total:0,
      areaList:[],
      orderType:[],
      orderStatus:[],
      dialogVisible:false,
      goodsTypeIds:[],
      goodsBrandIds:[],
      warehouseIds:[],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },

      permission: {
        add: ['admin', 'reportBuyStatistics:add'],
        edit: ['admin', 'reportBuyStatistics:edit'],
        del: ['admin', 'reportBuyStatistics:del'],
        import: ['admin', 'reportBuyStatistics:import'],
        export: ['admin', 'reportBuyStatistics:export'],
        copy: ['admin', 'reportBuyStatistics:copy'],
        upload: ['admin', 'reportBuyStatistics:upload'],
        download: ['admin', 'reportBuyStatistics:download']
      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
      dataExtent:[],
      groupColumn: [],
      goodsId:null,
      warehouseId:null,
      storehouseId: null,
      goodsBrandId: null,
      goodsTypeId: null,
      goodsTagId: null,
      deptId: null,
      userId: null,
      customerId: null,
      barcode: null,
      multiple: true,
      groupColumnSelectList:[],
      groupColumnList: [{
        label: '商品',
        value: 'goodsId'
      },{
        label: '供应商',
        value: 'customerId'
      },{
        label: '商品品牌',
        value: 'goodsBrandId'
      },{
        label: '商品分类',
        value: 'goodsTypeId'
      },{
        label: '商品类型',
        value: 'goodsTagId'
      },{
        label: '采购部门',
        value: 'deptId'
      },{
        label: '采购员',
        value: 'userId'
      },{
        label: '仓库',
        value: 'warehouseId'
      },{
        label: '条形码',
        value: 'barcode'
      }]
    }
  },
  watch: {
    'groupColumnSelectList':{
      handler(n){
        let groupColumn =this.groupColumnSelectList.join(',')
        this.$set(this.query,'groupColumn',groupColumn)
      },
      deep: true
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getChange(val){
      this.groupColumnSelectList = val
      console.log("!!!!!!!!!!!!!!!!")
      console.log(this.groupColumnSelectList)
    },
    // getValue(e){
    //   this.query.startDate = this.dataExtent[0]
    //   this.query.endDate = this.dataExtent[1]
    // },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
    init(){
      this.page = 1
    },
    onGet(){
      const that =this

      let groupColumn =this.groupColumnSelectList.join(',')
      get({...this.query,groupColumn:groupColumn}).then(res=>{
        that.crud.data = res.data.content
        that.crud.page.total = res.data.totalElements
        console.log(that.total)
      })
    },
    resetQuery(){
      this.query = {
        customerIds:null,
        customerKeyword:'',
        endDate:null,
        orderCode:null,
        orderType: null,
        goodsKeyword:'',
        goodsTypeIds:null,
        goodsBrandIds:null,
        orderRemark:'',
        goodsRemark: '',
        orderStatus: null,
        warehouseIds: null,
        startDate:null,
        page:1,
        size:10,
      }
      this.goodsTypeIds = []
      this.orderType  = []
      this.goodsBrandIds = []
      this.orderStatus  = []
      this.warehouseIds = []
      this.dataExtent = []
      this.crud.resetQuery()
      this.onGet()
    },
    queryReport(){
      this.query.goodsTypeIds = this.goodsTypeIds.length?this.goodsTypeIds.join(','):''
      this.query.orderType = this.orderType.length?this.orderType.join(','):''
      // this.query.goodsBrandIds = this.goodsBrandIds.length?this.goodsBrandIds.join(','):''
      this.query.orderStatus = this.orderStatus.length?this.orderStatus.join(','):''
      // this.query.warehouseIds= this.warehouseIds.length?this.warehouseIds.join(','):''
      this.init()
      this.onGet()
      this.crud.props.searchToggle = false
    },
    getGroupColumn(){
      let str = ''
      for(let i=0;i<this.groupColumnSelectList.length;i++){
        const group = this.groupColumnList.find(val=> val.value == this.groupColumnSelectList[i])
        str+=i<this.groupColumnSelectList.length?`${group.label}:${group.value}|`:`${group.label}:${group.value}`
      }

      return str
    }
  },

}

</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .flex{
    display: flex;
  }
  .fow-reverse{
    flex-direction: row-reverse;
  }
  .float{
    float: left;
  }
</style>
